package com.wangchao.administrator.zenmechi.ui.fragment.homefragment;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.wangchao.administrator.zenmechi.R;
import com.wangchao.administrator.zenmechi.bean.homebean.GoodsHotListBean;

import java.util.List;

/**
 * Created by My on 2016/10/18.
 */
public class ListAdapter extends BaseAdapter{
    private  List<GoodsHotListBean> goodsHotList;
    private Context context;

    public ListAdapter(Context context, List<GoodsHotListBean> goodsHotList) {

        this.context = context;
        this.goodsHotList = goodsHotList;
    }


    @Override
    public int getCount() {
        return goodsHotList.size();
    }

    @Override
    public Object getItem(int i) {
        return goodsHotList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }
    ViewHolder viewHolder;
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view==null)
        {
            view= LayoutInflater.from(context).inflate(R.layout.item_image,null);
            viewHolder=new ViewHolder();
            viewHolder.imageView= (ImageView) view.findViewById(R.id.iv_image);
            view.setTag(viewHolder);
        }
        else {
            viewHolder= (ViewHolder) view.getTag();
        }
        Glide.with(context).load(goodsHotList.get(i).getPic()).into(viewHolder.imageView);

        return view;
    }
    public static class ViewHolder{
        ImageView imageView;
    }
}
